package com.dkd.manage.openai;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/deepseek")
@CrossOrigin(origins = "http://localhost:5173") // 允许前端跨域访问
public class DeepseekController {

    private final DeepseekService deepseekService;

    @Autowired
    public DeepseekController(DeepseekService deepseekService) {
        this.deepseekService = deepseekService;
    }

    @PostMapping("/chat")
    public String chat(@RequestBody Map<String, String> request) {
        String prompt = request.get("prompt");
        if (prompt == null || prompt.isEmpty()) {
            return "Prompt cannot be empty";
        }
        return deepseekService.chatWithDeepseek(prompt);
    }
}
